import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Set;

public class RedisTest {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {

        }
    }

    //hset 和 hget
    public static void testHsetAndHget(Jedis jedis) {

        jedis.hset("key", "name", "zhangsan");
        jedis.hset("key", "age", "20");

        String name = jedis.hget("key", "name");
        System.out.println(name);

        String age = jedis.hget("key", "age");
        System.out.println(age);
    }

    //hexists 和 hdel
    public static void testHexistsAndHdel(Jedis jedis) {
        boolean exists = jedis.hexists("key", "name");
        System.out.println(exists);

        jedis.hdel("key", "name");
        exists = jedis.hexists("key", "name");
        System.out.println(exists);
    }

    //hkeys 和 hvals
    public static void testHkeysAndHvals(Jedis jedis) {

        jedis.hset("key", "name", "zhangsan");
        jedis.hset("key", "age", "20");

        Set<String> keys = jedis.hkeys("key");
        System.out.println(keys);

        List<String> vals = jedis.hvals("key");
        System.out.println(vals);
    }

    //hmget
    public static void testHmget(Jedis jedis) {
        jedis.hset("key", "name", "zhangsan");
        jedis.hset("key", "age", "20");

        List<String> vals = jedis.hmget("key", "name", "age");
        System.out.println(vals);
    }

    //hlen
    public static void testHlen(Jedis jedis) {
        jedis.hset("key", "name", "zhangsan");
        jedis.hset("key", "age", "20");

        long len = jedis.hlen("key");
        System.out.println(len);
    }

    //hincrby 和 hincrbyfloat
    public static void testHincrbyAndHincrbyfloat(Jedis jedis) {
        jedis.hset("key", "age", "20");

        long age = jedis.hincrBy("key", "age", 10);
        System.out.println(age);

        double score = jedis.hincrByFloat("key", "score", 10.0);
        System.out.println(score);
    }
    
}